package com.lb.trac.web;

import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;

public class JSStore implements JSObject{

	private final String jsName = "Ext.data.Store";
	
	private String storeId;
	private JSONArray fields=new JSONArray();
	private List<String> fieldList = new ArrayList<String>();
	
	public JSStore addField(String fieldName){
		fieldList.add(fieldName);
		return this;
	}
	
	public String getFields(){
		fields.put(fieldList);
		StringWriter sw = new StringWriter();
		try {
			fields.write(sw);
		} catch (JSONException e) {
			e.printStackTrace();
			return e.getMessage();
		}
		return sw.toString();
	}
	
	public String getJSName() {
		return jsName;
	}

	public String getStoreId() {
		return storeId;
	}

	public void setStoreId(String storeId) {
		this.storeId = storeId;
	}
}
